// var i;
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PlatformButton = require("./AL_GAME_HUA_PlatformButton");
// var AL_GAME_HUA_PlatformManager = require("./AL_GAME_HUA_PlatformManager");
// var p = cc._decorator;
// var f = p.ccclass;
// var d =
//     (p.property,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.record = [];
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.onLoad = function () {
//             var t = this;
//             "wx" == ailin_sdk_manager.getSysPlatformName() &&
//             AL_GAME_HUA_GameConst.GameConst.getInstance().feedback_enabled
//                 ? (AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.ON_FEED_BACK_HIDE,
//                       function (e) {
//                           if (e.node) {
//                               e.hide
//                                   ? (-1 == t.record.indexOf(e.node) && t.record.push(e.node), t.hide())
//                                   : (t.record.remove(e.node), 0 == t.record.length && t.show());
//                           }
//                       },
//                       this
//                   ),
//                   e.prototype.onLoad.call(this))
//                 : (this.node.active = !1);
//         };
//         t.prototype.chuangjian_anniu = function () {
//             return AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().wx.createFeedbackButton({
//                 type: "text",
//                 text: " ",
//                 style: {
//                     backgroundColor: "#00000001",
//                     color: "#ffffff01"
//                 }
//             });
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//             if (e.prototype.onDestroy) {
//                 e.prototype.onDestroy.call(this);
//             }
//         };
//         return __decorate([f], t);
//     })(AL_GAME_HUA_PlatformButton.default));
// exports.default = d;


// 引入各个模块和类
const GameConst = require("./AL_GAME_HUA_GameConst");
const Define = require("./AL_GAME_HUA_Define");
const PlatformButton = require("./AL_GAME_HUA_PlatformButton");
const PlatformManager = require("./AL_GAME_HUA_PlatformManager");

// 通过装饰器定义类
const { ccclass, property } = cc._decorator;

/** 
 * @class ButtonManager
 * @extends PlatformButton
 * 用于管理平台反馈按钮的类
 */
@ccclass
class ButtonManager extends PlatformButton.default {
    // 记录按钮的节点
    record = [];

    /**
     * 加载时的初始化逻辑
     */
    onLoad() {
        const self = this;
        
        // 检测当前平台是不是微信平台并且反馈功能是开启的
        if (ailin_sdk_manager.getSysPlatformName() === "wx" && GameConst.GameConst.getInstance().feedback_enabled) {
            // 注册事件监听器
            AL_APP_SDK_MANAGER.on(
                Define.GameEvent.ON_FEED_BACK_HIDE,
                function (event) {
                    if (event.node) {
                        // 隐藏
                        if (event.hide) {
                            if (!self.record.includes(event.node)) {
                                self.record.push(event.node);
                            }
                            self.hide();
                        } else {
                            // 删除节点
                            self.record = self.record.filter(node => node !== event.node); 
                            if (self.record.length === 0) {
                                self.show();
                            }
                        }
                    }
                },
                this
            );
            super.onLoad();
        } else {
            this.node.active = false;
        }
    }

    /**
     * 创建反馈按钮
     * @returns {Object} 返回创建的反馈按钮对象
     */
    chuangjian_anniu() {
        return PlatformManager.PlatformManager.getInstance().wx.createFeedbackButton({
            type: "text",
            text: " ",
            style: {
                backgroundColor: "#00000001",
                color: "#ffffff01"
            }
        });
    }

    /**
     * 销毁时的回调函数
     */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
        if (super.onDestroy) {
            super.onDestroy.call(this);
        }
    }
}

exports.default = ButtonManager;